package killerqueen.game.objects;

import killerqueen.game.interfaces.GameObject;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;

public class Edge implements GameObject {

  
  private float x1;
  private float y1;
  private float x2;
  private float y2;

  private PolygonShape edge;
  private Body body;

  public Edge() {
  }


  @Override
  public void init(World world, String id) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(0, 0);
    body = world.createBody(bodyDef);

    edge = new PolygonShape();

    Vec2 pointA = new Vec2(x1, y1);
    Vec2 pointB = new Vec2(x2, y2);

    edge.setAsEdge(pointA, pointB);

    body.createFixture(edge, 0);
  }

  @Override
  public void paint(Graphics g) {
    g.pushTransform();

    Vec2 pos = body.getPosition();
    float angle = body.getAngle();
    g.translate(pos.x, pos.y);
    g.rotate(0, 0, (float) Math.toDegrees(+angle));
    g.setColor(Color.green);
    g.drawLine(edge.getVertex(0).x, edge.getVertex(0).y, edge.getVertex(1).x, edge.getVertex(1).y);

    g.popTransform();
  }

  @Override
  public void update(long delta) {
    // Empty
  }

  @Override
  public void input(Input input) {
    // Empty
  }


public void setX1(float x1) {
	this.x1 = x1;
}


public void setY1(float y1) {
	this.y1 = y1;
}


public void setX2(float x2) {
	this.x2 = x2;
}


public void setY2(float y2) {
	this.y2 = y2;
}


@Override
public void destroy(World world) {
	// TODO Auto-generated method stub
	
}
}
